home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / CCDBMS.ZIP / DBASE.H < prev    next >
C/C++ Source or Header  |  1997-03-18  |  2KB  |  82 lines

  1. // =================================================================
  2. // Dbase.h
  3. // =================================================================
  4. // Harold Kasperink / John Dekker 
  5. // Dr. Dobb's Journal 1997
  6. // =================================================================
  7. // Dbase command class 
  8. // =================================================================
  9. #ifndef _DBASE_H_
  10. #define _DBASE_H_
  11.  
  12. #include <string.h>
  13. #include "thread.h"
  14. #include "mutex.h"
  15. #include "dbcmd.h"
  16.  
  17. class CArrayDbase;
  18.  
  19. ////////////////////////////////////////////////////////////////////
  20. // CDbase
  21. ////////////////////////////////////////////////////////////////////
  22. class CDbase : public CThread
  23. {
  24. private:
  25.     friend class     CArrayDbase;
  26.  
  27.     // Lockes usage of object
  28.     CMutex        m_mtxInuse;    
  29.     // Instruct dbase-thread to do command
  30.     CMutex        m_mtxStartSql;    
  31.     // Informs instruct-thread command is done
  32.     CMutex        m_mtxEndSql;    
  33.     // Make sure no parallel usage of do 
  34.     CMutex        m_mtxDoCmd;        
  35.     // User name
  36.     char*            m_pszUsr;        
  37.     // User password
  38.     char*            m_pszPsswd;        
  39.     // Database connect string
  40.     char*            m_pszDb;        
  41.     // boolean flag indicates if connected
  42.     boolean            m_bConnected;    
  43.     // Continue flag
  44.     boolean            m_bContinue;    
  45.     // Current command
  46.     CDbCommand*        m_pCommand;        
  47.     // Return code of command execution
  48.     long            m_lSql;            
  49.  
  50. public:
  51.     CDbase();
  52.     virtual ~CDbase();
  53.  
  54.     // Command functions
  55.     long            Do(CDbCommand &command);
  56.  
  57.     // Commit
  58.     void            Commit(boolean bUnlock=TRUE);
  59.  
  60.     // Rollback
  61.     void            Rollback(boolean bUnlock=TRUE);
  62.  
  63. private:
  64.     // Thread loop overwrite
  65.     virtual    void    Process();
  66.  
  67.     // Inuse Funtions
  68.     boolean            TryLock();
  69.     void            Lock();
  70.     void            Unlock();
  71.  
  72.     // Connect functions
  73.     void            ConnectInfo(const char *szUsr, const char *szPasswd, const char *szDB);
  74.     void            DeleteConnectInfo();
  75.     long            Connect();
  76.     void            Disconnect();
  77. };
  78.  
  79. #endif
  80.  
  81.  
  82.